package com.vdong.common.oauth.common.exception;


import com.vdong.common.oauth.common.enums.ResultCodeEnum;
import com.vdong.common.oauth.common.function.APIResult;
import com.vdong.common.oauth.common.pojo.ResultCodeInter;

public class WebBizException extends RuntimeException {

    private ResultCodeInter resultCode;

    public WebBizException(ResultCodeInter rc) {
        super(rc.getMessage());
        ResultCodeCase resultCodeCase = new ResultCodeCase();
        resultCodeCase.setCode(rc.getCode());
        resultCodeCase.setMessage(rc.getMessage());
        this.resultCode = resultCodeCase;
    }

    public WebBizException(ResultCodeInter rc, String message) {
        super(message);
        ResultCodeCase resultCodeCase = new ResultCodeCase();
        resultCodeCase.setCode(rc.getCode());
        resultCodeCase.setMessage(message);
        this.resultCode = resultCodeCase;
    }

    public WebBizException(String message) {
        super(message);
        ResultCodeCase resultCodeCase = new ResultCodeCase();
        resultCodeCase.setCode(ResultCodeEnum.FAIL.getCode());
        resultCodeCase.setMessage(message);
        this.resultCode = resultCodeCase;
    }

    protected class ResultCodeCase implements ResultCodeInter {

        private Integer code;

        private String message;

        @Override
        public Integer getCode() {
            return code;
        }

        @Override
        public String getMessage() {
            return message;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }

    public ResultCodeInter getResultCode() {
        return resultCode;
    }

    @Override
    public String toString() {
        return new APIResult(resultCode).toString();
    }
}
